package com.xxxx.server.config.security.config;


import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

@Configuration
public class CaptchatConfig {

    @Bean
    public DefaultKaptcha defaultKaptcha(){
        //验证码生成器
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        /*配置文件*/
        Properties properties = new Properties();
        /*带边框*/
        properties.setProperty("kaptcha.border","yes");
        /*边框颜色*/
        properties.setProperty("kaptcha.border.color","105,179,90");
        //验证码
        properties.setProperty("kaptcha.session.key","code");
        //验证码字体颜色 默认黑色
        properties.setProperty("kaptcha.textproducer.font.color","blue");
        properties.setProperty("kaptcha.textproducer.font.name","宋体,楷体,微软雅黑");
        properties.setProperty("kaptcha.textproducer.font.size","30");
        //字符长度
        properties.setProperty("kaptcha.textproducer.char.length","4");
        //字符间距 默认为2
        properties.setProperty("kaptcha.textproducer.char.space","4");

        //图宽度和高度
        properties.setProperty("kaptcha.image.width","100");
        properties.setProperty("kaptcha.image.height","40");
        //配置封装起来
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }


}
